<?php
/************************
* Simple News Engine 0.2.3
* author: Ragnaar <ragnaar@km.ru>
* home: http://code.google.com/p/sne-news
* date: 08.06.2011
*********************/
define('_VALID_SNE', '1');
define('SNE_PATH', dirname(__FILE__)); //определяем путь

require_once SNE_PATH."/inc/config.php";
require_once SNE_PATH."/inc/connect.php";
require_once SNE_PATH."/inc/functions.php";
require_once SNE_PATH."/inc/FeedWriter.php";

//Creating an instance of FeedWriter class.
$feed = new FeedWriter(RSS2);

//Setting the channel elements
//Use wrapper functions for common channel elements
$feed->setTitle($rssTitle);
$feed->setLink($rssLink);
$feed->setDescription($rssDescription);

//Image title and link must match with the 'title' and 'link' channel elements for valid RSS 2.0
$feed->setImage($rssImage[0], $rssImage[1], $rssImage[2]);

//Retriving informations from database addin feeds
if (isset($_GET['full'])){
    $query = prefix("SELECT * FROM `{prefix}news` WHERE `pub` = 1 ORDER BY `id` DESC LIMIT 0, $rssLenght", $dbprefix);

} else {
    $query = prefix("SELECT `id`, `title`, SUBSTRING(`text`,1, LOCATE('<hr id=\"cut\">', `text`) -1) AS `text`, `cut`, `image`, `date`, `pub` FROM `{prefix}news` WHERE `pub` = 1 ORDER BY `id` DESC LIMIT 0, $rssLenght", $dbprefix) ;

}
$rows = mysql_query($query);

while($row = mysql_fetch_object($rows)){
//Create an empty FeedItem
    $newItem = $feed->createNewItem();

//Add elements to the feed item
    $newItem->setTitle($row->title);
    $newItem->setLink($newsPath.'?mode=news&id='.$row->id);
    $newItem->setDate($row->date);
    $newItem->setDescription(str_replace('<hr id="cut">', '', $row->text));

//Now add the feed item
    $feed->addItem($newItem);
}

//OK. Everything is done. Now genarate the feed.
$feed->genarateFeed();

?>